/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.concurrent.TimeUnit;

/**
 * <p>Project: javase2203 - T12
 * <p>Powered by webrx On 2022-08-09 14:25:32
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class T12 {
    void work() {
        String t = Thread.currentThread().getName();
        System.out.println(t + "启动");
        while (true) {
            try {
                Thread.sleep(1000);
                System.out.println(t);
            } catch (Exception e) {
                break;
            }
        }
        System.out.println(t + "结束");
    }

    public static void main(String[] args) {
        T12 t = new T12();
        Thread tt = new Thread(t::work);
        tt.start();


        try {
            TimeUnit.SECONDS.sleep(2);
            tt.interrupt();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
